var relateposturl = location.href;
var relatedlabel =''; 
if (relateposturl.indexOf('?relatedlabel=')!=-1){ 
	relatedlabel = relateposturl.substring(relateposturl.indexOf('?relatedlabel=')+14, relateposturl.length).replace(/%20/ig,' ');
	relatedlabel = decodeURIComponent(relatedlabel); 
}
var nextlabel = 0; 
var nextTitles = new Array(); 
var nextTitlesNum = 0; 
var nextUrls = new Array(); 
function next_results_labels(json){ 
	var firstfound = 0; 
	for (var i = json.feed.entry.length-1; i >= 0; i--) { 
		var entry = json.feed.entry[i];
		for (var k = 0; k < entry.link.length; k++){
			if (entry.link[k].rel == 'alternate'){
				if (firstfound==1){
					nextTitles[nextTitlesNum] = entry.title.$t;
					nextUrls[nextTitlesNum] = entry.link[k].href+'?relatedlabel='+vlabel; nextTitlesNum++; break;
				} 
				if(relateposturl.match(entry.link[k].href)!=null) {firstfound=1;}
			}
		} 
		if (nextTitlesNum==maxnext){break;}
	} 
	printnextLabels(); 
} 
function printnextLabels() {
	if (nextTitles.length > 0) {
		var i = 0;
		var html = '<div style="margin-bottom:10px;"><span style="font:bold 16px Arial;">'+nexttitle+'</span><ul>';
		while (i < nextTitles.length && i < 20) {
			html+='<li><a href="' + nextUrls[i] + '">' + nextTitles[i] + '</a></li>';
			i++; 
		} 
		html+='</ul></div>';
		document.getElementById('next-posts').innerHTML += html; 
	} else{ 
		document.getElementById('next-posts').innerHTML = ''; 
	} 
} 
var prevlabel = 0; 
var prevTitlesNum = 0; 
var prevTitles = new Array(); 
var prevUrls = new Array(); 
function prev_results_labels(json) { 
	var firstfound = 0; 
	for (var i = 0; i < json.feed.entry.length ; i++) { 
		var entry = json.feed.entry[i];
		for (var k = 0; k < entry.link.length; k++){
			if (entry.link[k].rel == 'alternate'){
				if (firstfound==1){
					prevTitles[prevTitlesNum] = entry.title.$t;
					prevUrls[prevTitlesNum] = entry.link[k].href+'?relatedlabel='+vlabel;
					prevTitlesNum++;
					break;
				} 
				if(relateposturl.match(entry.link[k].href)!=null) {firstfound=1;}
			}
		} 
		if (prevTitlesNum==maxprev){break;}
	} 
	printprevLabels(); 
} 
function printprevLabels() { 
	if (prevTitles.length > 0) { 
		var i = prevTitles.length-1; 
		var html = '<div style="margin-bottom:10px;"><span style="font:bold 16px Arial;">'+prevtitle+'</span><ul>';
		while (i >= 0 && i < 20) {
			html += '<li><a href="' + prevUrls[i] + '">' + prevTitles[i] + '</a></li>';
			i--;
		} 
		html+='</ul></div>'; 
		document.getElementById('prev-posts').innerHTML += html; 
	} else {
		document.getElementById('prev-posts').innerHTML = '';
	}
}